import * as PageJumpService from '../../services/Editor/pageJump';

export default {
    namespace: 'pageJump',
    state: {},
    reducers: {
        updatePageJump(state, { payload: pageJump }) {
            return { ...state, ...pageJump };
        },
    },
    effects: {
        *fetchPageJump({ payload: query }, { call, put, select }) {
            const fetched = yield select(state => state.pageJump.fetched);
            const outOfDate = yield select(state => state.data.outOfDate);
            if (!fetched || outOfDate) {
                const { data: pageJump } = yield call(PageJumpService.fetch, query);
                pageJump.fetched = true;
                yield put({ type: 'updatePageJump', payload: pageJump });
            }
        },
    },
    subscriptions: {

    },
};
